import 'package:crm/components/ui/loader.dart';
import 'package:crm/enum/enum.dart';
import 'package:crm/utils/styles.dart';
import 'package:crm/utils/themcolor.dart';
import 'package:crm/utils/theme_utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/screenutil.dart';
class CustomerPage extends StatefulWidget {
  CustomerPage({Key key}) : super(key: key);

  @override
  _CustomerPageState createState() => _CustomerPageState();
}

class _CustomerPageState extends State<CustomerPage>
    with SingleTickerProviderStateMixin {
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  TabController _controller;
  List<Tab> tabs = [Tab(text: '公司'), Tab(text: '代理商')];
  List list = [];
  LoaderState _status = LoaderState.Loading;
  bool isDarkMode;
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(seconds: 2), () {
      if (mounted) {
        setState(
          () {
            _status = LoaderState.Succeed;
          },
        );
      }
    });
    list..add({})..add({})..add({});
    _controller = TabController(length: tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    isDarkMode = ThemeUtils.isDark(context);
    return Theme(
      data: ThemeData(
        canvasColor: ThemeUtils.getDialogBackgroundColor(context),
        brightness: isDarkMode ? Brightness.dark : Brightness.light,
        primaryColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
        accentColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
        iconTheme: IconThemeData(
            color: isDarkMode ? Colours.bg_gray_ : Colours.dark_bg_gray_),
        textTheme: TextTheme(
          // TextField输入文字颜色
          subtitle1: isDarkMode ? TextStyles.textDark : TextStyles.text,
          // Text文字样式
          bodyText2: isDarkMode ? TextStyles.textDark : TextStyles.text,
          subtitle2:
              isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
        ),
        scaffoldBackgroundColor: ThemeUtils.getBackgroundColor(context),
        appBarTheme: AppBarTheme(
          iconTheme: IconThemeData(color: ThemeUtils.getIconColor(context)),
          elevation: 0.0,
          brightness: isDarkMode ? Brightness.dark : Brightness.light,
          color: ThemeUtils.getBackgroundColor(context),
        ),
      ),
      child: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Image.network(
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1062073197,554843147&fm=26&gp=0.jpg',
            width: 95,
            height: 42.5,
            fit: BoxFit.cover,
          ),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.menu),
              onPressed: () {
                print('object');
                _scaffoldKey.currentState.openEndDrawer();
              },
            ),
          ],
          centerTitle: true,
          bottom: TabBar(
            tabs: tabs,
            labelColor: Colors.blue,
            unselectedLabelColor: ThemeUtils.getIconColor(context),
            indicatorColor: ThemeUtils.getIconColor(context),
            controller: _controller,
            indicatorSize: TabBarIndicatorSize.label,
            labelStyle: TextStyle(fontSize: 16),
          ),
        ),
        body: LoaderContainer(
          loaderState: _status,
          contentView: TabBarView(
            controller: _controller,
            children: <Widget>[
              _left(),
              _left(),
            ],
          ),
        ),
        endDrawer: Drawer(
          child: ConstrainedBox(
            constraints: const BoxConstraints(minWidth: 350),
            child: Material(
              child: ListView.builder(
                itemCount: 50,
                itemBuilder: (BuildContext context, int index) {
                  return Text('data$index');
                },
              ),
            ),
          ),
        ),
      ),
    );
  }

  Widget _left() {
    return EasyRefresh(
      // footer: BallPulseFooter(),
      // header: ,
      onLoad: () async {
        // setState(
        //   () {
        //     list..add({})..add({})..add({});
        //   },
        // );
      },
      onRefresh: () async {},
      child: ListView.builder(
          physics: const AlwaysScrollableScrollPhysics(),
          itemBuilder: (BuildContext context, int index) {
            return _leftList();
          },
          itemCount: list.length),
    );
  }

  Widget _leftList() {
    return Container(
      margin: EdgeInsets.all(10.0),
      padding: EdgeInsets.only(right: 10.0),
      decoration: BoxDecoration(
        color: ThemeUtils.getDialogBackgroundColor(context),
        boxShadow: [
          BoxShadow(
              color: Colors.black12,
              offset: Offset(0.0, 15.0), //阴影xy轴偏移量
              blurRadius: 15.0, //阴影模糊程度
              spreadRadius: 1.0 //阴影扩散程度
              )
        ],
        borderRadius: BorderRadius.all(
          Radius.circular(10.0),
        ),
      ),
      height: ScreenUtil().setHeight(200),
      child: InkWell(
        onTap: () {
          print('object');
        },
        child: Row(
          children: <Widget>[
            Expanded(
              flex: 1,
              child: Center(
                child: Icon(Icons.assignment),
              ),
            ),
            Expanded(
              flex: 5,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text('安徽柠徽信息工程有限公司'),
                  Text('创建人:张远涛'),
                  FittedBox(
                      child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text('创建:2020-06-04'),
                      Text('最后跟进:2020-06-04'),
                    ],
                  ))
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
